$(document).ready(function() {
$('a[name=terms]').click(function(e) {
e.preventDefault();

hide_flash();

//var id = $(this).attr('href');
var id = ('.window');

var arrayPageScroll = document.viewport.getScrollOffsets();
var scrolltop = arrayPageScroll[1];
var scrollleft = arrayPageScroll[0];

var maskHeight = $(document).height();
var maskWidth = $(window).width();

var winH = $(window).height();
var winW = $(window).width();

 if ($(id).height() > winH) {
   var winH = $(id).height();
 }

 if ($(id).width() > winW) {
   var winW = $(id).width();
 }

 if (maskHeight < (scrolltop + $(id).height() + (winH/2-$(id).height()/2))) {
   var maskHeight = (scrolltop + $(id).height() + (winH/2-$(id).height()/2));
 }
 
 if (maskWidth < (scrollleft + $(id).width() + (winW/2-$(id).width()/2))) {
   var maskWidth = (scrollleft + $(id).width() + (winW/2-$(id).width()/2));
 }

$(id).css('top', scrolltop + (winH/2-$(id).height()/2));
$(id).css('left', scrollleft + (winW/2-$(id).width()/2));

$('#mask').css({'width':maskWidth,'height':maskHeight});
$('#mask').fadeTo(500,0.8,function(){$(id).fadeIn(500);$('.close').fadeTo(100, 0.5)});

});

$('.window .close').mouseover(function (e) {
e.preventDefault();
$('.close').fadeTo(300, 1);
});

$('.window .close').mouseout(function (e) {
e.preventDefault();
$('.close').fadeTo(200, 0.5);
});

$('.window .close').click(function (e) {
e.preventDefault();
$('.window').fadeOut(500,function(){$('#mask').fadeOut(500);show_flash();});
});
$('#mask').click(function (e) {
e.preventDefault();
$('.window').fadeOut(500,function(){$('#mask').fadeOut(500);show_flash();});
});
});

function hide_flash() {
	document.getElementById('capcha').style.display = "none";
}


function show_flash() {
	document.getElementById('capcha').style.display = "inline";
}